/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-06-17     donying   add port file
 */
#include "w5500_dev.h"
#include <rtthread.h>
#include "drv_spi.h"
#include "setting.h"
#include <stdlib.h>
#include "wiz.h"

extern device_param_t device_setting;

static struct net_device_wiz wiz0 =
{
    WIZ_SPI_DEVICE,

    "00-E0-81-DC-53-1A"
};

int w5500_spi_device_init()
{
    __HAL_RCC_GPIOB_CLK_ENABLE();
    return rt_hw_spi_device_attach("spi2", WIZ_SPI_DEVICE, GPIOB, GPIO_PIN_12);
}
INIT_DEVICE_EXPORT(w5500_spi_device_init);

int w5500_device_register(void)
{
    struct net_device_wiz *w5500 = &wiz0;
    char mac[18] = {0};
    rt_sprintf(mac, "%02X-%02X-%02X-%02X-%02X-%02X", device_setting->netdev_params.hwaddr[0],
                    device_setting->netdev_params.hwaddr[1],
                    device_setting->netdev_params.hwaddr[2],
                    device_setting->netdev_params.hwaddr[3],
                    device_setting->netdev_params.hwaddr[4],
                    device_setting->netdev_params.hwaddr[5]);
    w5500->mac = mac;
    return wiz_init(w5500);
}
